/*
	Matrix.h

		Matrix manipulation.

	Author:	Brett Porter
	Email: brettporter@yahoo.com
	Website: http://rsn.gamedev.net/pl3d
	Copyright (C)2000, 2001, Brett Porter. All Rights Reserved.
	This source code is released under the LGPL. See license.txt for details.

	Created: 9 December 2000
	Last Edited: 8 January 2001

	Please see the file ChangeLog.html for a revision history.
*/

#pragma once

#include "Quaternion.h"
#include "Rotator.h"


namespace _FOGGE_
{
	namespace _UTIL_
	{
		
		namespace _MATH_
		{
			class Vector;

			class Matrix
			{
				public:
					/*	Constructor. */
					Matrix();

					/*	Destructor. */
					~Matrix();

					/*	Set to identity. */
					void loadIdentity();

					/*	Set the values of the matrix. */
					void set( const float *matrix );

					/*	Post-multiply by another matrix. */
					void postMultiply( const Matrix& matrix );

					/*	Set the translation of the current matrix. Will erase any previous values. */
					void setTranslation( const Vector* translation );

					/*	Set the inverse translation of the current matrix. Will erase any previous values. */
					void setInverseTranslation( const Vector* translation );

					void setRotation( const Rotator& rot );

					void setInverseRotation( const Rotator& rot );

					
					/*	Make a rotation matrix from a quaternion. The 4th row and column are unmodified. */
					void setRotationQuaternion( const Quaternion& quat );

					
					/*	Get the matrix data. */
					const float *getMatrix() const { return m_matrix; }

					/*	Translate a vector by the inverse of the translation part of this matrix. */
					void inverseTranslateVect( Vector* vect  ) const;

					/*	Rotate a vector by the inverse of the rotation part of this matrix. */
					void inverseRotateVect( Vector* vect ) const;

				private:
					//	Matrix data, stored in column-major order
					float m_matrix[16];
			};

			inline void Matrix::set( const float *matrix )
			{
				memcpy( m_matrix, matrix, sizeof( float )*16 );
			}

			inline void Matrix::loadIdentity()
			{
				memset( m_matrix, 0, sizeof( float )*16 );
				m_matrix[0] = m_matrix[5] = m_matrix[10] = m_matrix[15] = 1;
			}

		}
	}
}
